class Solution {
public:
    int eraseOverlapIntervals(vector<vector<int>>& g) {
        int n=g.size();
        sort(g.begin(),g.end());
        int left=g[0][0];
        int right=g[0][1];
        int ret=0;
        for(int i=1;i<n;++i)
        {
            if(right>g[i][0])
            {
                ret++;
                right=min(right,g[i][1]);
            }
            else 
            {
                left=g[i][0];
                right=g[i][1];
            }
        }
        return ret;
    }
};
